<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/14
 * Time: 10:58
 */

namespace app\admin\model;


class ActivityBoxPrize extends DataBase
{
    protected $name = 'activity_box_prize';
    protected $autoWriteTimestamp = 'true';

    public function getTypeAttr($value)
    {
        if($value == 1){
            return '普通礼物';
        }elseif($value == 2){
            return '座驾';
        }
    }
    public function getStatusAttr($value)
    {
        $status = [0=>'不显示',1=>'显示'];
        return $status[$value];
    }
    public function getIsNoticeAttr($value)
    {
        $status = [0=>'不提示',1=>'有提示'];
        return $status[$value];
    }

    public function getDataList()
    {
        $page_config = array(
            'page' => input('get.offset',1),
            'list_rows' =>input('get.limit',10)
        );
        $where = [];
        if(!empty(input('key')) && !empty(input('value'))){
            $key = input('key'); $value = input('value');
            if($key=='id') $where[] = [$key,'=',$value];
            switch($key=='type'){
                case '普通礼物': $where[] = [$key,'=',1];break;
                case '座驾': $where[] = [$key,'=',2];break;
            }
            switch($key=='status'){
                case '显示': $where[] = [$key,'=',1];break;
                case '不显示': $where[] = [$key,'=',2];break;
            }

        }
        $order = input('sort', 'id') . ' ' . input('order', 'desc');
        $data = $this->where($where)->order($order)->paginate($page_config);
        foreach($data as $key => $value){
            if($value['type'] == '普通礼物'){
                $data[$key]['gift_name'] = Gift::where('id='.$value['type_id'])->value('gift_name');
            }
            if($value['type'] == '座驾'){
                $data[$key]['gift_name'] = Vehicle::where('vehicle_id='.$value['type_id'])->value('vehicle_name');
            }
        }
        return $data;
    }
}